package com.boot.mall.cart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * 购物车对象
 */

public class Cart {

    private List<CartItem> items;   //购物项
    private Integer countNum;   //总商品数量
    private Integer countType;  //总商品类型数量
    private BigDecimal totalAmount; //总价
    private BigDecimal reduce;  //减免价

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {  //计算购物项的商品总数
        int count = 0;
        if (items != null && items.size() > 0){
            for (CartItem item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        if (items != null && items.size() > 0){
            return items.size();
        }else {
            return 0;
        }
    }

    public BigDecimal getTotalAmount() {    //计算总价
        BigDecimal totalPrice = new BigDecimal(0);
        if (items != null && items.size() > 0){
            for (CartItem item : items) {
                // 对购物项商品是否选中进行判断，被选中添加到总价当中
                if (item.getCheck()) {
                    totalPrice = totalPrice.add(item.getTotalPrice());
                }
            }
        }
        return totalPrice;
    }

    // TODO 减免后面做
    public BigDecimal getReduce() {
        return reduce;
    }

}
